package minh.bac.wcbrazil2014.listviewmatch;

import java.util.ArrayList;

import com.viewpagerindicator.PageIndicator;

import minh.bac.wcbrazil2014.R;
import minh.bac.wcbrazil2014.WCTAG;
import minh.bac.wcbrazil2014.adapter.LichDauVPgerAdapter;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.view.ViewPager;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

public class ViewPagerLichDau extends Fragment {
	
	static FragmentManager fragmentManager;
	private PageIndicator mIndicator;
	private ViewPager mViewPager;
	private LichDauVPgerAdapter mLichDauVPgerAdapter;
	private ArrayList<ListViewFragment> mListFragmentData; 
	
	
	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		View rootView = inflater.inflate(R.layout.viewpager_lichdau, container, false);
		Log.d("LISTMatch", "listmatch createview");
		mViewPager = (ViewPager) rootView.findViewById(R.id.pager_lichdau);
		mIndicator = (PageIndicator) rootView.findViewById(R.id.indicatorTitle);
		mListFragmentData = new ArrayList<ListViewFragment>();
		LoadListFragment();
		//
		mLichDauVPgerAdapter = new LichDauVPgerAdapter(this.getChildFragmentManager(), mListFragmentData);
		//
		mViewPager.setAdapter(mLichDauVPgerAdapter);
		//		
		mIndicator.setViewPager(mViewPager);	
		return rootView;
	}
	public void LoadListFragment()
	{
		ListViewFragment vongbangFM = ListViewFragment.newsInstance(WCTAG.TYPE_SHOW_VONGBANG);
		ListViewFragment vong18FM = ListViewFragment.newsInstance(WCTAG.TYPE_SHOW_VONG18);
		ListViewFragment vongtuketFM = ListViewFragment.newsInstance(WCTAG.TYPE_SHOW_VONGTUKET);
		ListViewFragment vongbanketFM = ListViewFragment.newsInstance(WCTAG.TYPE_SHOW_VONGBANKET);
		ListViewFragment vongGiai34FM = ListViewFragment.newsInstance(WCTAG.TYPE_SHOW_VONGGIAI34);
		ListViewFragment vongchungketFM = ListViewFragment.newsInstance(WCTAG.TYPE_SHOW_VONGCHUNGKET);
		//add
		mListFragmentData.add(vongbangFM);
		mListFragmentData.add(vong18FM);
		mListFragmentData.add(vongtuketFM);
		mListFragmentData.add(vongbanketFM);
		mListFragmentData.add(vongGiai34FM);
		mListFragmentData.add(vongchungketFM);
	}
	public static void switchFragment(int idContainer, Fragment fragment ,boolean addToBackStack, String TAG)
	{
		if(addToBackStack)
		{
			if( TAG!= null )
			{
				fragmentManager.beginTransaction().replace(idContainer, fragment, TAG).addToBackStack(TAG).commit();
				
			}
			else
			{
				fragmentManager.beginTransaction().replace(idContainer, fragment).addToBackStack(null).commit();
			}
		}
		else
		{
			if( TAG!= null )
			{
				fragmentManager.beginTransaction().replace(idContainer, fragment, TAG).commit();
			}
			else
			{
				fragmentManager.beginTransaction().replace(idContainer, fragment).commit();
			}
		}
	}

}
